// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2004-11-18

#ifndef __BASE_BUFFER_H_COMMON_SVR_BASE__
#define __BASE_BUFFER_H_COMMON_SVR_BASE__

#pragma once

namespace JoyServer
{

// for high performance memory allocation.
// used by sockets as data buffers.
//##ModelId=44CEFAD1016C
class CJoyBuffer
{
protected:
	//##ModelId=44CEFAD10177
    void*   m_buf;
	//##ModelId=44CEFAD10178
    int     m_size;
	//##ModelId=44CEFAD10179
    int     m_allocSize;
public:
	//##ModelId=44CEFAD1017A
    CJoyBuffer();
	//##ModelId=44CEFAD1017B
    CJoyBuffer(int nSize);
	//##ModelId=44CEFAD10186
    CJoyBuffer(const void* buf, int nSize);
	//##ModelId=44CEFAD10189
    ~CJoyBuffer();

	//##ModelId=44CEFAD1018A
    bool IsEmpty() const
    {
        return m_size == 0;
    }
	//##ModelId=44CEFAD1018C
    int GetSize() const
    {
        return m_size;
    }
	//##ModelId=44CEFAD1018E
    void* GetBuffer()
    {
        return m_buf;
    }
	//##ModelId=44CEFAD1018F
    const void* GetBuffer() const
    {
        return m_buf;
    }

	//##ModelId=44CEFAD10196
    void SetSize(int nSize);
	//##ModelId=44CEFAD10198
    void RemoveAll();
	//##ModelId=44CEFAD10199
    void Remove(void* start, void* stop);
	//##ModelId=44CEFAD1019C
    void Remove(void* stop);
	//##ModelId=44CEFAD1019E
    void Append(const void* buf, int len);
	//##ModelId=44CEFAD101A5
    void BatchAppend(const void* const * bufs, int* lens, int count);
	//##ModelId=44CEFAD101A9
    void Replace(int relPos, int relLen, const void* buf, int len);
};


} // namespace JoyServer

#endif  // __BASE_BUFFER_H_COMMON_SVR_BASE__
